/*Author Rajith Chathunga,
 *		 Computer Science and Engineering,
 *		 University of Moratuwa.
 *
 * Class name : SportNews
 * 
 *  			
 * This class stores sports categories and their URLs. And also send them to the QNews class.
 *  This class extends Activity and implements onClickListener.*/

package chathunga.qNews;


import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


public class SportNews extends Activity implements OnClickListener {
	ListView lv;
	String ss,sss;
	ImageView img;
	TextView optn;
	Bundle b = new Bundle();
	NewsObjects no;
	private ArrayList<Object> ar=new ArrayList<Object>();

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sportnews); 
        img=(ImageView)findViewById(R.id.qn);
        lv=(ListView)findViewById(R.id.sportlist);
        optn=(TextView)findViewById(R.id.addn);
        optn.setOnClickListener(this);
        img.setOnClickListener(this);
        data();
                                                         
        lv.setAdapter(new ArrayAdapter<Object>(this,R.layout.list_black_text,R.id.list_content , ar));
        lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
        Toast.makeText(getBaseContext(), ""+ar.get(arg2), Toast.LENGTH_LONG).show();
        
        ss=ar.get(arg2).toString();
        no=(NewsObjects) ar.get(arg2);
        sss=no.toStr();
        	operation();
        	
	}
        });
	
}
	//This method contains sport categories and rss URLs in an ArrayList
	public void data(){
		
		ar.add(new NewsObjects("WORLD","http://wwos.ninemsn.com.au/rss/headlines/"));
        ar.add(new NewsObjects("FOOTBALL",""));
        ar.add(new NewsObjects("CRICKET",""));
        ar.add(new NewsObjects("TENNIS","http://feeds2.feedburner.com/Tennis-AtpWorldTourHeadlineNews"));
        ar.add(new NewsObjects("RUGBY","http://www.bignewsnetwork.com/?rss=dff6b204fdf35a9d"));
        ar.add(new NewsObjects("GOLF","http://www.bignewsnetwork.com/?rss=af4e74a975da4c65"));
        ar.add(new NewsObjects("BOXING","http://www.bignewsnetwork.com/?rss=fd229789e4db5aad"));
        ar.add(new NewsObjects("RACING","http://www.bignewsnetwork.com/?rss=adb3cb482df59870"));
        ar.add(new NewsObjects("ATHLETICS","http://www.paralympic.org/rss/general_news.rss"));	
        
	}
	//This method is called when click on a sport country.
	public void operation(){
		
		if(ss=="FOOTBALL"){
			
		Intent it= new Intent(this,FootblNews.class);
	
		startActivity(it);
		
		}
		if(ss=="CRICKET"){
			
			Intent it= new Intent(this,CricNews.class);
		
			startActivity(it);
			
			}
		if(ss=="TENNIS"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			
			}
		if(ss=="RUGBY"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			
			}
		if(ss=="GOLF"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			}
		if(ss=="BOXING"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			
			}
		if(ss=="RACING"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			}
		if(ss=="ATHLETICS"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			
			}
		if(ss=="WORLD"){
			
			Intent it= new Intent(this,QNews.class);
			
			b.putString("key", sss);

			it.putExtras(b);
			
			startActivity(it);
			
			}
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.qn){
			
			this.finish();
			
			Intent bToHome= new Intent(this,MainQNews.class);
			
			startActivity(bToHome);
			
			finish();
		}
		if(v.getId()==R.id.addn){
			
			Intent it= new Intent(this,Option.class);
			
			startActivity(it);
		}
		
	}
		
	}